{include file='common/head' /}
<!-- 表情开始 -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Begin emoji-picker Stylesheets -->
<link href="__PLURING__/emoji/lib/css/nanoscroller.css" rel="stylesheet">
<link href="__PLURING__/emoji/lib/css/emoji.css" rel="stylesheet">
<!-- End emoji-picker Stylesheets -->
<!-- 表情结束 -->

    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <input type="hidden" name="cover" id="cover" value="{$data.cover|default=''}">
                    <input type="hidden" name="id"  value="{$data.id|default=0}">
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend>商品选择操作：</legend>
                      </fieldset>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            选择商品分类
                        </label>
                        <!-- 分类 -->
                        <div class="layui-col-md1">
                            <select id="goods_cid" style="width:150px;" name="cid" lay-verify="" lay-search>
                                <option selected value="">分类-可输入搜索值</option>
                                {volist name="goodtypes" id="v"}
                                    <option value="{$key}">{$v}</option>
                                {/volist}
                            </select>
                        </div>
                        <!-- 选择品牌 -->
                        <div class="layui-col-md1">
                            <select id="goods_bid" style="width:150px;" name="bid" lay-verify="" lay-search>
                                <option selected value="">品牌-可输入搜索值</option>
                                {volist name="goodBs" id="v"}
                                    <option value="{$key}">{$v}</option>
                                {/volist}
                            </select>
                        </div>
                        <!-- 商品名称 -->
                        <div class="layui-col-md1">
                            <input id="goods_name" placeholder="商品标题" type="text" name="goods_name" value="" autocomplete="off" class="layui-input">                      
                        </div>
                        <!-- 商品序号 -->
                        <div class="layui-col-md1">
                            <input id="goods_id" placeholder="商品序号" type="number" name="goods_id" value="" autocomplete="off" class="layui-input">                      
                        </div>
                        &nbsp;&nbsp;
                        <div class="layui-col-md1">
                            <button onclick="getGoodsList()" title="搜索商品" class="layui-btn"  type="button" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                        <div class="layui-col-md3">
                            <button onclick="allCheckClik(true)" title="商品全选" class="layui-btn layui-btn-normal"  type="button" lay-filter="sreach"><i class="layui-icon layui-icon-snowflake"></i>商品当前全选</button>
                            <button onclick="allCheckClik(false)" title="商品取消全选" class="layui-btn layui-btn-warm"  type="button" lay-filter="sreach"><i class="layui-icon layui-icon-snowflake"></i>商品取消全选</button>
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            需要先搜索才能显示商品
                            <input id="copyText" type="text" name="copyText" style="width: 10px;opacity: 0;" value=""/>
                        </div>
                    </div>
                    <!-- 选择商品 -->
                    <div class="layui-col-md11">
                        <div id="goodsList" style="
                        overflow-y: auto;
                        max-height: 400px;
                        padding: 10px;
                        border: 1px solid #01AAED;
                        border-left: none;
                        border-right: none;">
                        </div>
                    </div>
                    <style>
                        .yulanClickGoods > div {
                            border:1px dashed #999;
                            margin-right:10px;
                            /* padding-left:8px; */
                            padding: 5px;
                            text-align: center;
                            border-radius: 6px;
                            width:300px;
                        }
                    </style>
                    <script>

                        function getGoodsList(obj = null){
                            if(!obj) {
                                obj = {
                                    cid:  $("#goods_cid").select().val(),
                                    bid:  $("#goods_bid").select().val(),
                                    name: $("#goods_name").val(),
                                    goods_id: $("input[name=goods_id]").val()
                                }
                            }

                            var num = layer.msg('加载中',{icon:4})
                            $.ajax({
                                url:"{:url('Product/getGoods')}",
                                type: "get",
                                data:obj,
                                dataType:"json",
                                success:function (res) {
                                    if(res.code == 200 && res.data){
                                        layer.msg('加载商品成功',{icon:6})
                                        var html = ``;
                                        var data = res.data.data
                                        if(data.length == 0){
                                            $("#goodsList").html('')
                                            $(".yulanClickGoods").html('')
                                            return layer.msg('抱歉，搜索不到该商品信息',{icon:5})
                                            //return layer.alert('抱歉，搜索不到该商品信息')
                                        }
                                        window.GOODS_DATA_LIST = {}
                                        for(var i = 0; i < data.length;i++){
                                            //onclick="checkIdClick(${data[i].id})"
                                            html += `
                                                    <div class="goodsItem" title="${data[i].name}" style="float: left;
    cursor: pointer;
    border: 1px solid #b9c2c5;
    padding: 8px;
    border-radius: 5px;
    border-style: dashed;
    margin-right: 10px;
    margin-bottom:10px;">
                                                            <div class="goodsCheckBox">
                                                                <input lay-filter="goodsIds" id="${'goodsId_'+data[i].id}" type="checkbox" value="${data[i].id}" title="${data[i].name ? data[i].name.substr(0,10)+'...' : ''}" name="goods_ids" lay-skin="primary">
                                                                <img style="height:80px;width:80px;border:1px solid #999;padding:3px;border-radius:4px;" src="${data[i].cover.split(',')[0]}"/>
                                                            </div>
                                                            <hr/>
                                                            <div>
                                                                <button type="button" onclick="copyCode('${data[i].name}')" title="点我复制名称" class="layui-btn layui-btn-normal" type="button" lay-filter="sreach"><i class="layui-icon layui-icon-snowflake"></i>名称</button>
                                                                <button type="button" onclick="copyCode('${data[i].id}')" title="点我复制序号" class="layui-btn layui-btn-normal" type="button" lay-filter="sreach"><i class="layui-icon layui-icon-snowflake"></i>序号</button>
                                                                <button type="button" onclick="openUrl('${data[i].supply_url}')" title="点我打开货源链接" class="layui-btn layui-btn-normal" type="button" lay-filter="sreach"><i class="layui-icon layui-icon-snowflake"></i>货源</button>
                                                            </div>
                                                    </div>
                                            `;  
                                            window.GOODS_DATA_LIST[data[i].id] = data[i]
                                        }
                                        if(html){
                                        setTimeout(function(){
                                            // 监听复选框
                                            $("#goodsList").html(html)
                                            $(".yulanClickGoods").html('')
                                            layui.form.render()
                                            setTimeout(function(){
                                                  //监听复选框-单个
                                                LAYUI_FORM.on('checkbox(goodsIds)', function(data){
                                                        // console.log(data,data.elem.checked,data.value)
                                                        // if(data.elem.checked==true){

                                                        // }else{

                                                        // }
                                                    viewGoodIdsList()
                                                });
                                            },100)
                                        },50)
                                        }
                                    }else{
                                        layer.alert(res.msg, {icon:2,time:1000});
                                    }
                                },
                                error:function(e){
                                    layer.alert("网络错误", {icon:5,time:1000});
                                },
                            });
                        }

                        function copyCode(title){
                            $("#copyText").val(title)
                            setTimeout(function(){
                                var copy=document.getElementById("copyText");
                                copy.select(); // 选择对象
	                            document.execCommand("Copy"); // 执行浏览器复制命令
                            },50)
	                        layer.msg('复制成功：'+title,{icon: 6})
                        }

                        // 选择表单
                        function checkIdClick(id){
                            // $('#goodsId_'+id).prop('checked') ?  $('#goodsId_'+id).attr('checked',false) : $('#goodsId_'+id).attr('checked',true)//$('#goodsId_'+id).click()
                        }

                        // 全选
                        function allCheckClik(bool = true){
                            layer.msg(bool ? '全选成功' : '取消成功',{icon: 6});
                            bool ?  $('input[name="goods_ids"]').prop('checked',true) : $('input[name="goods_ids"]').prop('checked',false),$('input[name="goods_ids"]').removeAttr('checked') 
                            // bool ?  $('input[name="goods_ids"]').prop('checked',true) : $('input[name="goods_ids"]').removeAttr('checked')
                            setTimeout(function(){
                                layui.form.render('checkbox')
                                setTimeout(function(){
                                    bool ? viewGoodIdsList() : $(".yulanClickGoods").html('')
                                },100)
                            },50)
                        }
                    </script>
                    <hr>
                    <!-- 预览选中商品 -->
                    <div id="yuLanShangPinView" class="layui-form-item">
                        <label class="layui-form-label">
                            预览商品
                        </label>
                        <div class="layui-col-md10">
                            <div style="overflow: auto;max-height: 300px;" class="yulanClickGoods">

                            </div>
                        </div>
                    </div>
                    <hr>
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend>用户选择操作：</legend>
                      </fieldset>
                    <!-- 选择会员快捷操作 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            选择会员操作
                        </label>
                        <div class="layui-col-md9">
                            <div class="layui-col-md3">
                                <input name="user_id" placeholder="随机用户人数" class="layui-input" value="1" type="number" />
                            </div>
                            <div class="layui-col-md6">
                                <button onclick="suijiUser(true)" title="随机用户" class="layui-btn layui-btn-danger"  type="button" ><i class="layui-icon layui-icon-edit"></i>随机用户</button>
                                <button onclick="suijiUser(false)" title="新增随机用户" class="layui-btn layui-btn-normal"  type="button"><i class="layui-icon layui-icon-addition"></i>新增用户</button>
                                <!-- <button onclick="allCheckClikUser(true)" title="用户全选" class="layui-btn layui-btn-normal"  type="button" lay-filter="sreach"><i class="layui-icon layui-icon-snowflake"></i>用户全选</button> -->
                                <button onclick="allCheckClikUser(false)" title="用户取消全选" class="layui-btn layui-btn-warm"  type="button" lay-filter="sreach"><i class="layui-icon layui-icon-snowflake"></i>用户取消全选</button>
                                用户数量：<span class="layui-badge layui-bg-blue">{$count}</span>
                            </div>
                        </div>
                    </div>
                    <!-- 选择会员 -->
                    <div class="layui-form-item">
                        <div class="layui-col-md11">
                            <div class="userListBox" style="overflow-y: auto;max-height: 400px;padding: 10px;border: 1px solid #1E9FFF;border-left: none;border-right: none;">
                                {volist name="users" id="v"}
                                    <div>
                                        <input lay-filter="usersIds" id="userId_{$v.id}" type="checkbox" name="uids" value="{$v.id}" title="{$v.nickname}" lay-skin="primary"> 
                                        <img src="{$v.avatarurl}" style="width:50px;height:50px;"/>
                                    </div>
                                {/volist}
                            </div>
                        </div>
                        
                        <style>
                            .userListBox div {
                                float: left;
                                border: 1px solid #999;
                                padding: 6px;
                                margin-right: 6px;
                                margin-bottom: 6px;
                                border-style: dashed;
                                border-radius: 5px;
                            }
                        </style>
                    </div>
                    <hr>
                    <!-- 预览用户 -->
                    <div id="yuLanUSERView" class="layui-form-item">
                        <label class="layui-form-label">
                            预览用户
                        </label>
                        <div class="layui-col-md10">
                            <div style="overflow: auto;max-height: 300px;" class="yuLanUSERViewCLICK">

                            </div>
                        </div>
                    </div>
                    <style>
                        .yuLanUSERViewCLICK > div {
                            border: 1px dashed #999;
                            margin-right: 10px;
                            padding: 5px;
                            text-align: center;
                            border-radius: 6px;
                        }
                    </style>
                    <hr>
                    <script>
                        window.USERLIST = {:json_encode($users)};
                        window.USERLISTOBJ = {}
                        if(window.USERLIST && window.USERLIST.length > 0)
                            for(var i  =0;i < window.USERLIST.length;i++) window.USERLISTOBJ[window.USERLIST[i].id] = window.USERLIST[i]
                        // 随机用户
                        function suijiUser(bool = true){
                            //var num = Math.floor(USERLIST.length / 10) + Math.floor(Math.random() *  (USERLIST.length / 10 + 5)) 
                            var num = Math.floor($("input[name=user_id]").val())
                            var list =  getRandomArrayElements(USERLIST, num)
                            if(bool){
                                $("input[name='uids']").prop('checked',false)
                            }
                            for(var i = 0; i <list.length;i++){
                                $("#userId_"+list[i].id).prop('checked',true)
                            }
                            setTimeout(function(){
                                layui.form.render('checkbox')
                                setTimeout(function(){
                                    // 渲染用户
                                    viewUsersIdsList()
                                },100)
                            },50)
                            layer.msg('随机成功',{icon:6})
                        }

                        // 取消全选或者  当前全选
                        function allCheckClikUser(bool = true){
                            bool ? $("input[name='uids']").prop('checked',true) : $("input[name='uids']").prop('checked',false)
                            setTimeout(function(){
                                layui.form.render('checkbox')
                                setTimeout(function(){
                                    // 渲染用户
                                    viewUsersIdsList()
                                    !bool && $(".yuLanUSERViewCLICK").html('')
                                },100)
                            },50)
                            layer.msg(bool ? '全选用户成功' : '取消全选成功',{icon:6})
                        }

                        function getRandomArrayElements(arr, count) {
                            arr = arr.sort(randomsort);
                            var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
                            while (i-- > min) {
                                index = Math.floor((i + 1) * Math.random());
                                temp = shuffled[index];
                                shuffled[index] = shuffled[i];
                                shuffled[i] = temp;
                            }
                            return shuffled.slice(min);
                        }


                        // 随机打乱用户
                        function randomsort(a, b) {
                            return Math.random()>.5 ? -1 : 1;
                            //用Math.random()函数生成0~1之间的随机数与0.5比较，返回-1或1
                        }
                    </script>
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend>常规操作如下：</legend>
                      </fieldset>
                      <!-- 最近天数 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            随机天数
                        </label>
                        <div class="layui-col-md3">
                            <input type="number" class="layui-input" id="min_day" value="15">
                            <input type="number" class="layui-input" id="max_day" value="200">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            第一个是最近天数，第二个是最早天数
                        </div>
                    </div>
                    <!-- 日期范围 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            日期范围
                        </label>
                        <div class="layui-col-md3">
                            <span style="display: none;">{$date_str = date('Y-m-d',time() - 3600*24 * rand(30,200)) .' - '.date('Y-m-d',time() - 3600*24 * rand(1,30))}</span>
                            <!-- 2020-07-16 - 2020-08-16 -->
                            <input type="text" class="layui-input" name="dateYmd" id="dateYmd" value="{$date_str}" placeholder="{$date_str}">
                        </div>
                        <div class="layui-col-md3">
                            <button title="随机日期" onclick="suijiDate()" type="button" class="layui-btn layui-btn-danger"><i class="layui-icon layui-icon-edit"></i>随机日期</button>
                        </div>
                    </div>
                    <script>
                        // 随机日期
                        function suijiDate(){
                            var min = $("#min_day").val()
                            if(!min || min < 0 ) min = 1;
                            var max = $("#max_day").val()
                            if(!max || max > 999) max = 999;
                            var str = getDateYmdStr(getRandomDateBetween(min,max).toLocaleDateString()) +" - " + getDateYmdStr(getRandomDateBetween(0,min).toLocaleDateString())
                            layer.msg('随机日期为：'+str+' 设置ok',{icon:6})
                            $("#dateYmd").attr('value',str).attr('placeholder',str).val(str)
                        }
                    </script>

                    <!-- 评分等级 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            评分等级
                        </label>
                        <div class="layui-col-md6">
                            <div id="rote-level"></div>
                            <input type="hidden"  name="level" autocomplete="off" class="layui-input" value="5">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            评分等级，值取1-5
                        </div>
                    </div>
                    <!-- 评论内容 -->
                    <style>
                        .emoji-wysiwyg-editor.layui-textarea {
                            height:100px;
                        }
                    </style>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            评论内容
                        </label>
                        <div class="layui-col-md6">
                            <input style="height:100px;" id="discussTxt" style="height:100px;" placeholder="请输入内容" name="discuss" class="layui-textarea" value="{$data.discuss|default=''}" data-emojiable="true"/>
                        </div>
                    </div>

                    <!-- 表情开始--- -->
                    <script src="__PLURING__/jq.js"></script>
                    <script>window.jQuery || document.write('<script src="js/jquery-2.1.1.min.js"><\/script>')</script>
                    <!-- Begin emoji-picker JavaScript -->
                    <script src="__PLURING__/emoji/lib/js/nanoscroller.min.js"></script>
                    <script src="__PLURING__/emoji/lib/js/tether.min.js"></script>
                    <script src="__PLURING__/emoji/lib/js/config.js"></script>
                    <script src="__PLURING__/emoji/lib/js/util.js"></script>
                    <script src="__PLURING__/emoji/lib/js/jquery.emojiarea.js"></script>
                    <script src="__PLURING__/emoji/lib/js/emoji-picker.js"></script>
                    <!-- End emoji-picker JavaScript -->
                    <script>
                    $(function() {
                      // Initializes and creates emoji set from sprite sheet
                      window.emojiPicker = new EmojiPicker({
                        emojiable_selector: '[data-emojiable=true]',
                        assetsPath: '/static/pluring/emoji/lib/img/',
                        popupButtonClasses: 'fa fa-smile-o'
                      });
                      // Finds all elements with `emojiable_selector` and converts them to rich emoji input fields
                      // You may want to delay this step if you have dynamically created input fields that appear later in the loading process
                      // It can be called as many times as necessary; previously converted input fields will not be converted again
                      window.emojiPicker.discover();
                    });
                      </script>
                    <!-- 表情结束--- -->

                    <!-- 评论图片 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            评论图片
                        </label>
                        <div class="layui-col-md9">
                            <div id="bannerListImgs">
                                <div>
                                    <input name="bannerDataImgs" type="hidden" value="{$data.cover|default=''}"/>
                                    <!-- 添加 -->
                                    <button title="添加新的轮播图-推荐" style="position: relative;" type="button" class="layui-btn layui-btn-normal">
                                        <input style="cursor: pointer;height:100%;width:100%;position: absolute;top:0;left:0;opacity: 0;" id="bannerImgs_data_push" type="file" size="30" name="bannerImgs_data_push" value="添加图片" multiple=true/>
                                        <i class="layui-icon layui-icon-praise"></i>
                                        添加上传
                                    </button>
                                    <!-- 替换 -->
                                    <button title="替换会删除原有的轮播图-不推荐" style="position: relative;" type="button" class="layui-btn layui-btn-warm">
                                        <input style="cursor: pointer;height:100%;width:100%;position: absolute;top:0;left:0;opacity: 0;" id="bannerImgs_data" type="file" size="30" name="bannerImgs_data[]" value="替换图片" multiple=true/>
                                        <i class="layui-icon layui-icon-upload-circle"></i>
                                        替换上传
                                    </button>
                                    <!-- 批量删除 -->
                                    <button title="直接清空当前轮播图" type="button" onclick='bannerDelAll()' class="layui-btn layui-btn-danger"><i class="layui-icon layui-icon-delete"></i>清空</button>
                                    <table class="layui-table">
                                        <thead>
                                            <th>图片</th>
                                            <th>操作</th>
                                        </thead>
                                        <tbody id="bannerListImgs-tbody">
                                            {if isset($data.cover) && $imgs && is_array($imgs)}
                                            {volist name="imgs" id="v"}
                                            <tr data-name="{$v}">
                                                <td> <img style="cursor: pointer;" title="点我预览图片" data-src="{$v}" onclick="lookImg('{$v}','商品-轮播图',this)" style="width:150px;"  src="{$v}" /></td>
                                                <td>
                                                    <button title="替换图片" style="position: relative;" type="button" class="layui-btn layui-btn-normal">
                                                        <input style="cursor: pointer;height:100%;width:100%;position: absolute;top:0;left:0;opacity: 0;" class="bannerList_tiHuan" type="file" size="30" name="bannerImgs_data_push" value="添加图片" multiple=true/>
                                                        <i class="layui-icon layui-icon-edit"></i>替换
                                                    </button>
                                                    <button title="向上排序" type="button" class="layui-btn layui-btn-warm layui-btn- layui-btn-xs" onclick="bannerViewValueSort(this,true)"><i class="layui-icon layui-icon-up"></i>&nbsp;向上</button>
                                                    <button title="向下排序" type="button" class="layui-btn layui-btn-warm layui-btn- layui-btn-xs" onclick="bannerViewValueSort(this,false)"><i class="layui-icon layui-icon-down"></i>&nbsp;向下</button>
                                                    <button title="删除" type="button" class="layui-btn layui-btn-danger layui-btn- layui-btn-xs" onclick="bannerViewdel(this)"><i class="layui-icon layui-icon-delete"></i>&nbsp;删除</button>
                                                </td>
                                            </tr>
                                            {/volist}
                                            {/if}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- <div class="layui-form-item">
                        <label class="layui-form-label">
                            评论图片
                        </label>
                        <div class="layui-col-md9">
                            <div id="demo" class="demo" style="width: 650px; height: 400px;">
                            </div>
                        </div>
                    </div> -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">回复内容</label>
                        <div class="layui-col-md9">
                            <input style="height:100px;" placeholder="请输入内容" name="reply" class="layui-textarea" value="{$data.reply|default=''}" data-emojiable="true"/>
                        </div>
                    </div>
                    <!-- 表情开始--- -->
                    <script src="__PLURING__/jq.js"></script>
                    <script>window.jQuery || document.write('<script src="js/jquery-2.1.1.min.js"><\/script>')</script>
                    <!-- Begin emoji-picker JavaScript -->
                    <script src="__PLURING__/emoji/lib/js/nanoscroller.min.js"></script>
                    <script src="__PLURING__/emoji/lib/js/tether.min.js"></script>
                    <script src="__PLURING__/emoji/lib/js/config.js"></script>
                    <script src="__PLURING__/emoji/lib/js/util.js"></script>
                    <script src="__PLURING__/emoji/lib/js/jquery.emojiarea.js"></script>
                    <script src="__PLURING__/emoji/lib/js/emoji-picker.js"></script>
                    <!-- End emoji-picker JavaScript -->
                    <script>
                    $(function() {
                      // Initializes and creates emoji set from sprite sheet
                      window.emojiPicker = new EmojiPicker({
                        emojiable_selector: '[data-emojiable=true]',
                        assetsPath: '/static/pluring/emoji/lib/img/',
                        popupButtonClasses: 'fa fa-smile-o'
                      });
                      // Finds all elements with `emojiable_selector` and converts them to rich emoji input fields
                      // You may want to delay this step if you have dynamically created input fields that appear later in the loading process
                      // It can be called as many times as necessary; previously converted input fields will not be converted again
                      window.emojiPicker.discover();
                    });
                      </script>
                    <!-- 表情结束--- -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-col-md9">
                            <input type="number" name="sort" value="{$data.sort|default=0}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            是否显示
                        </label>
                        <div class="layui-input-inline">
                            {if empty($data['is_display'])}
                            <input type="radio" name="is_display" value="1" title="是" checked>
                            <input type="radio" name="is_display" value="0" title="否" >
                            {else /}
                            <input type="radio" name="is_display" value="1" title="是" {if $data['is_display'] == 1}checked{/if}>
                            <input type="radio" name="is_display" value="0" title="否" {if $data['is_display'] == 0}checked{/if}>
                            {/if}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            匿名
                        </label>
                        <div class="layui-input-inline">
                            {if empty($data['is_anonymous'])}
                            <input type="radio" name="is_anonymous" value="1" title="是">
                            <input type="radio" name="is_anonymous" value="0" title="否" checked >
                            {else /}
                            <input type="radio" name="is_anonymous" value="1" title="是" {if $data['is_anonymous'] == 1}checked{/if}>
                            <input type="radio" name="is_anonymous" value="0" title="否" {if $data['is_anonymous'] == 0}checked{/if}>
                            {/if}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">确定保存</button></div>
                </form>
            </div>
        </div>
        <script>
            var level = 5;
            var reply = "<?php echo isset($data) && isset($data->discuss) && $data->discuss ? $data->discuss : '' ?>";
        </script>
        <script>
            layui.use(['form', 'layer','jquery','rate','laydate'],function() {
                $ = layui.jquery;
                var form = layui.form,layer = layui.layer;
                window.LAYUI_FORM = form;
                var rate = layui.rate;
                setTimeout(function(){
                    initGoods()
                },1)
                reply && $("textarea").val(reply)
                  //监听下拉框-单个
                //   LAYUI_FORM.on('select(pinglun_types)', function(data){
                //       viewHaoPingList(data.value)
                //         // console.log(data,data.elem.checked,data.value)
                //         // if(data.elem.checked==true){
                //
                //         // }else{
                //
                //         // }
                // });

                // 监听用户组列表               
                    setTimeout(function(){
                            //监听复选框-单个
                        LAYUI_FORM.on('checkbox(usersIds)', function(data){
                                // console.log(data,data.elem.checked,data.value)
                                // if(data.elem.checked==true){
                                    
                                // }else{
                                    
                                // }
                                viewUsersIdsList()
                        });
                    },100)


                 //日期范围
                layui.laydate.render({
                    elem: '#dateYmd',
                    range: true
                });

                //显示文字
                rate.render({
                    elem: '#rote-level'
                    ,value: level
                    ,text: true //开启文本
                });

                //监听提交
                form.on('submit(add)', function(data) {
                    if(window.AJAX_BOOL && window.AJAX_BOOL){
                        return layer.msg('当前请求加载数据中，稍等片刻',{icon:5});
                    }
                    var bannerImgStr =  bannerGetImgs()

                    // if(!bannerImgStr){
                    //     layer.msg('请上传轮播图',{icon:5})
                    //     return false;
                    // }
                    if(bannerImgStr){
                        data.field.bannerImgStr = bannerImgStr
                    }
                    
                    var layui = layer;
                    
                    var goodsIds = []
                    var goods = $("input[name=goods_ids]")
                    if(goods.length == 0 ) return layer.msg('必须选择商品',{icon:5});
                    // alert('商品ok')
                    for(var i = 0; i < goods.length;i++){
                        if($(goods[i]).next() && $(goods[i]).next().attr('class').indexOf('layui-form-checked') >= 0) {
                            goodsIds.push($(goods[i]).val())
                        }
                    }
                    // alert('选取完毕')
                    if(goodsIds.length ==0) return layer.msg('必须选择商品',{icon:5});
                    // alert('用户开始')
                    var uids = []
                    var udiDoms = $("input[name=uids]")
                    if(udiDoms.length == 0) return layui.msg('必须选择用户');
                    for(var i = 0; i < udiDoms.length;i++){
                        if($(udiDoms[i]).prop('checked')) uids.push($(udiDoms[i]).val())
                    }
                    if(uids.length ==0) return layui.msg('必须选择用户')
                    data.field.goodsIds = goodsIds
                    data.field.uids = uids
                    window.AJAX_BOOL = true;
                    $.ajax({
                        url:"{:url('Product/comment_add_pl')}",
                        type: "post",
                        data:data.field,
                        dataType:"json",
                        success:function (res) {
                            if(res.code == 200){
                                layer.alert(res.msg, {icon: 1},function () {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                            }else{
                                layer.alert(res.msg, {icon:2,time:1000});
                            }
                            window.AJAX_BOOL = false;
                        },
                        error:function(e){
                            window.AJAX_BOOL = false;
                            layer.alert("网络错误", {icon:5,time:1000});
                        },
                    });
                    return false;
                });
            });



            window.onload = function(){
                $("#rote-level ul > li").click(function(){
                    $("input[name=level]").val($("#rote-level > span").text()[0] - 0)
                })
            }
        </script>


<script>
    // 存储信息
    var bannerFilesObj = [];
    // 绑定事件-替换
    $("#bannerImgs_data").change(function(){
        var files = document.querySelector("input[name='bannerImgs_data[]']").files
        if(!files || files.length == 0) return layer.msg('请选择文件',{icon: 5})
        var form  = new FormData();
        form.append('prefix','goods_comment');
        for(var i = 0; i < files.length;i++){
            bannerFilesObj.push({
                size: files[i].size / 1024 + 'KB',
                type: files[i].type,
                name: files[i].name
            })
            form.append('file[]',files[i]);
        }
        uploadsImgsMores(form);
    })
    // 添加 - 图片
    $("#bannerImgs_data_push").change(function(){
        var files = document.querySelector("input[name='bannerImgs_data_push']").files
        if(!files || files.length == 0) return layer.msg('请选择文件',{icon: 5})
        var form  = new FormData();
        form.append('prefix','goods_comment');
        for(var i = 0; i < files.length;i++){
            bannerFilesObj.push({
                size: files[i].size / 1024 + 'KB',
                type: files[i].type,
                name: files[i].name
            })
            form.append('file[]',files[i]);
        }
        uploadsImgsMores(form,true);
    })

    // ajax 多文件请求
    function uploadsImgsMores(data,bool = false){
        $.ajax({
            url: '/admin/Uploads/cosFilesPl',    
            type: 'post',
            data,
            dataType : "json",
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success:function(res){
                if(res.code && res.code == 200 && res.data){
                    bannerView(res.data,bool)
                }
                layer.msg(res.msg || '操作ok',{icon: res.code == 200 ? 6 :5 })
            }
        })
    }


    // 渲染
    function bannerView(data,bool){
        if(!data || data.length == 0) return false;
        var html = ``;
        var sval = '';
        for(var i = 0; i < data.length;i++){
            sval +=  data[i].url + (i == data.length - 1  ? '' : ',');
            html += `
                <tr data-name="${data[i].url}">
                    <td> <img style="cursor: pointer;" title="点我预览图片" data-src="${decodeURIComponent(data[i].url)}" onclick="lookImg('${decodeURIComponent(data[i].url)}','商品-轮播图',this)" style="width:150px;"  src="${data[i].url}" /></td>
                    <td>
                        <button title="替换图片" style="position: relative;" type="button" class="layui-btn layui-btn-normal">
                            <input style="cursor: pointer;height:100%;width:100%;position: absolute;top:0;left:0;opacity: 0;" class="bannerList_tiHuan" type="file" size="30" name="bannerImgs_data_push" value="添加图片" multiple=true/>
                            <i class="layui-icon layui-icon-edit"></i>替换
                        </button>
                        <button title="向上排序" type="button" class="layui-btn layui-btn-warm layui-btn- layui-btn-xs" onclick="bannerViewValueSort(this,true)"><i class="layui-icon layui-icon-up"></i>&nbsp;向上</button>
                        <button title="向下排序" type="button" class="layui-btn layui-btn-warm layui-btn- layui-btn-xs" onclick="bannerViewValueSort(this,false)"><i class="layui-icon layui-icon-down"></i>&nbsp;向下</button>
                        <button title="删除" type="button" class="layui-btn layui-btn-danger layui-btn- layui-btn-xs" onclick="bannerViewdel(this)"><i class="layui-icon layui-icon-delete"></i>&nbsp;删除</button>
                    </td>
                </tr>
            `;
        }
        if(!bool){
            $("#bannerListImgs tbody").css('display','none').html(html)
            $("#bannerListImgs tbody").show(600); 
        }else{
            var htmlTr = $("#bannerListImgs tbody").css('display','none').html()
            $("#bannerListImgs tbody").html(htmlTr + html).show(600); 
        }
        setTimeout(function(){
            bannerList_TiHuanBtn()
        },500)
        $("input[name='bannerDataImgs']").val(sval)
    }

    // 向上 或者向下
    function bannerViewValueSort(self,bool){
        // 开始演员
        var f = $(self).parents('tr');
        var tit = ''
        var list = $("#bannerListImgs-tbody tr")
        var fname = $(f).attr('data-name')
        // 向上
        if(bool){
            if(!(list.length <= 2 || $(list[0]).attr('data-name') != fname))
                tit = '-已在最后面'
            $(f).hide(500,function() {
                setTimeout(function () {
                    if (tit.length == 0) {
                        $(f).show(500)
                        return $(f).prev().insertAfter(f);
                    }
                    var html = $(f).html();$(f).remove()
                    $("#bannerListImgs-tbody").append('<tr data-name="' +fname+'">' + html + '</tr>')
                },500)
            })
        // 向下
        }else{
            if(!(list.length <= 2 || $(list[list.length - 1]).attr('data-name') != fname))
                tit = '-已在最前面'
            $(f).hide(500,function() {
                setTimeout(function () {
                    if (tit.length == 0) {
                        $(f).show(500)
                        return $(f).next().insertBefore(f);
                    }
                    var html = $(f).html();$(f).remove()
                    $("#bannerListImgs-tbody").prepend('<tr data-name="' +fname+'">' + html + '</tr>')
                }, 500)
            })
        }
        layer.msg('切换顺序-' +  (bool ? ' 向上移动ok' : ' 向下移动ok')+tit,{icon:6})
    }

    // 删除
    function  bannerViewdel(self){
        layer.confirm('确定删除此图片?',{
            icon:4,
            title:'轮播图-删除'
        },function(index){
            $(self).parents('tr').remove();
            layer.msg('删除ok',{icon:6})
            layer.close(index)
        })
    }

    // 拿取到 图片数据
    function bannerGetImgs(){
        var imgs =  $("#bannerListImgs-tbody").find('img')
        if(!imgs || imgs.length == 0) return false;
        var s = '';
        for(var i = 0; i < imgs.length;i++){
            s += $(imgs[i]).attr('data-src') + (i == imgs.length - 1 ? '' : ',')
        }
        return s;
    }


    // 点我清空数据
function bannerDelAll(){
layer.confirm('是否清除当前轮播图数据?',{title:'轮播图操作',icon:3},function(index){
    layer.close(index)
    layer.msg('清除轮播图成功',{icon:6})
    $("#bannerListImgs-tbody").hide(300,function(){
        $("#bannerListImgs-tbody").html("")
    })
})
}

// 绑定事件
function bannerList_TiHuanBtn(){
                    $(".bannerList_tiHuan").off('change')
                    $(".bannerList_tiHuan").change(function(){
                        var f = $(this)[0].files
                        var self = this
                        if(f && f.length > 0){
                            var form = new FormData();
                            form.append('prefix','goods_banners');
                            form.append('file',f[0])
                            $.ajax({
                                url: '/admin/Uploads/uploadImg',    
                                type: 'post',
                                data: form,
                                dataType : "json",
                                async: true, // 是否异步
                                processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
                                contentType: false, //
                                success:function(res){
                                    if(res.code && res.code == 200 && res.data){
                                        var url = '/' + res.data.fileName + '/' + res.data.prefix+ '/' + res.data.url.replace("\\",'/') 
                                        var fElem = $(self).parents('tr')
                                        $(fElem).find('img').attr('src',url).attr('data-src',url)
                                        $(fElem).attr('data-name',url)
                                    }
                                    layer.msg(res.msg || '操作ok',{icon: res.code == 200 ? 6 :5 })
                                }
                            })
                        }
                    })
                }
</script>

<script>
    // 渲染选中商品
    function viewGoodIdsList(){
        //if(!window.GOODS_DATA_LIST) return   layui.msg('麻烦先搜下商品',{icon:5});
        var layui = layer
        var goodsIds = []
        var goods = $("input[name=goods_ids]")
        if(goods.length == 0 ) return   layui.msg('必须选择商品');
        // alert('商品ok')
        for(var i = 0; i < goods.length;i++)
            if($(goods[i]).next() && $(goods[i]).next().attr('class').indexOf('layui-form-checked') >= 0) goodsIds.push($(goods[i]).val())
        if(goodsIds && goodsIds.length >0){
            var html = ``;
            for(var i = 0;i < goodsIds.length;i++){
                var id = goodsIds[i]
                if(!window.GOODS_DATA_LIST || !window.GOODS_DATA_LIST[id]) continue;
                var linshiData = window.GOODS_DATA_LIST[id]
                html += `
                <div class="yulanClickGoodsItem" title="${linshiData.name}" style="float: left;cursor: pointer;padding-bottom: 8px;margin-bottom: 10px;">
                        <div title="${linshiData.id}-${linshiData.name}" onclick="openUrl('${linshiData.supply_url}')" style="display: flex;justify-content: space-evenly;">
                            <span style="text-align: left;">
                                名称：<span style="color:#1E9FFF;">${linshiData.name ? linshiData.name.substr(0,10)+'...' : ''}</span>
                                <hr>
                                序号：<span style="color:#1E9FFF;">${linshiData.id}</span>
                            </span>
                            <img style="height:50px;border:1px solid #999;padding:3px;border-radius:4px;" src="${linshiData.cover.split(',')[0]}"/>
                        </div>
                        <hr/>
                        <div>
                            <button type="button" class="layui-btn layui-btn-normal" onclick="copyCode('${linshiData.name}')" title="点我复制名称" ><i class="layui-icon layui-icon-snowflake"></i>名称</button>
                            <button type="button" class="layui-btn layui-btn-normal" onclick="copyCode('${linshiData.id}')" title="点我复制序号" ><i class="layui-icon layui-icon-snowflake"></i>序号</button>
                            <button type="button" class="layui-btn layui-btn-normal" onclick="openUrl('${linshiData.supply_url}')" title="点我跳转货源链接" ><i class="layui-icon layui-icon-snowflake"></i>货源</button>
                            <button data-id="${linshiData.id}" onclick="clickGoods(this,${linshiData.id})" type="button" class="layui-btn layui-btn-danger"  title="点我删除" ><i class="layui-icon layui-icon-delete"></i>删除</button>
                        </div>
                </div>
                `;
            }
            if(html){
                layer.msg('生成预览商品列表ok',{icon: 6})
                $(".yulanClickGoods").html(html)
            }else{
                $(".yulanClickGoods").html('')
            }
        }
    }

    // 删除列表中的商品
    function clickGoods(self,id){
        if(!id || !self) return layer.msg('错误值，刷新重试',{icon:5})
        $("#goodsId_"+id).prop('checked',false)
        setTimeout(function(){
            $(self).parents('.yulanClickGoodsItem').remove()
            layui.form.render('checkbox')
            layer.msg('删除成功',{icon:6})
        },100)
    }

    // 删除列表中的用户
    function clickUsersdel(self,id){
        if(!id || !self) return layer.msg('错误值，刷新重试',{icon:5})
        $("#userId_"+id).prop('checked',false)
        setTimeout(function(){
            $(self).parents('.yuLanUSERViewCLICKItem').remove()
            layui.form.render('checkbox')
            layer.msg('删除成功',{icon:6})
        },100)
    }

    // 选中用户列表渲染
    function viewUsersIdsList(){
        //if(!window.GOODS_DATA_LIST) return   layui.msg('麻烦先搜下商品',{icon:5});
        var uids = []
        var layui = layer
        var udiDoms = $("input[name=uids]")
        if(udiDoms.length == 0) return layui.msg('必须选择用户');
        for(var i = 0; i < udiDoms.length;i++) if($(udiDoms[i]).prop('checked')) uids.push($(udiDoms[i]).val())
        if(uids.length ==0) return layui.msg('必须选择用户')
        if(uids && uids.length >0){
            var html = ``;
            for(var i = 0;i < uids.length;i++){
                var id = uids[i]
                if(!window.USERLISTOBJ || !window.USERLISTOBJ[id]) continue;
                var linshiData = window.USERLISTOBJ[id]
                html += `
                <div class="yuLanUSERViewCLICKItem" title="昵称：${linshiData.nickname}-序号：${linshiData.id}" style="float: left;cursor: pointer;padding-bottom: 8px;margin-bottom: 10px;">
                        <div title="昵称：${linshiData.nickname}-序号：${linshiData.id}" onclick="openUrl('${linshiData.avatarurl}')" style="display: flex;justify-content: space-evenly;">
                            <span style="text-align: left;">
                                昵称：<span style="color:#1E9FFF;">${linshiData.nickname}</span>
                                <hr>
                                序号：<span style="color:#1E9FFF;">${linshiData.id}</span>
                            </span>
                            <img style="height:50px;border:1px solid #999;padding:3px;border-radius:4px;" src="${linshiData.avatarurl}"/>
                        </div>
                        <hr/>
                        <div>
                            <button type="button" class="layui-btn layui-btn-normal" onclick="copyCode('${linshiData.nickname}')" title="点我复制昵称" ><i class="layui-icon layui-icon-snowflake"></i>昵称</button>
                            <button type="button" class="layui-btn layui-btn-normal" onclick="copyCode('${linshiData.id}')" title="点我复制序号" ><i class="layui-icon layui-icon-snowflake"></i>序号</button>
                            <button data-id="${linshiData.id}" onclick="clickUsersdel(this,${linshiData.id})" type="button" class="layui-btn layui-btn-danger"  title="点我删除" ><i class="layui-icon layui-icon-delete"></i>删除</button>
                        </div>
                </div>
                `;
            }
            if(html){
                layer.msg('生成预览用户列表ok',{icon: 6})
                $(".yuLanUSERViewCLICK").html(html)
            }else{
                $(".yuLanUSERViewCLICK").html('')
            }
        }
    }
</script>

<script>
    // 跳转地址
    function openUrl(url){
        if(url && url.indexOf('http') >= 0)
            window.open(url,'_tagert');
        else 
            layer.msg('链接为空，跳转失败',{icon: 5})
    }   
</script>

<script>
    // 初始化商品数据
    function initGoods(){
        var obj = localStorage.getItem('comment_add_pl_caogaoList')
        if(obj) obj = JSON.parse(obj);
        if(obj && (obj.bid|| obj.cid)){
            if(obj.bid){
                $("select[name=bid]").find("option[value="+obj.bid+"]").prop("selected",true);
            }
            if(obj.cid){
                $("select[name=cid]").find("option[value="+obj.cid+"]").prop("selected",true);
            }
            layui.form.render('select')
            getGoodsList(obj)
            if(window.JISHIQI_comment_add_pl_caogaoList){
                window.clearInterval(window.JISHIQI_comment_add_pl_caogaoList)
            }
            // 监听数据 开始
            setInterval(function(){
                jianTingListForm()
            },500)
        }else{
            if(window.JISHIQI_comment_add_pl_caogaoList){
                window.clearInterval(window.JISHIQI_comment_add_pl_caogaoList)
            }
            // 监听数据 开始
            window.JISHIQI_comment_add_pl_caogaoList = setInterval(function(){
                jianTingListForm()
            },500)
        }
    }

    $(function(){
        bannerList_TiHuanBtn();
    })

    // 监听存储数据开始
    function jianTingListForm(){
        var obj = {
            // 分类
            cid: $("#goods_cid").select().val(),
            // 品牌
            bid: $("#goods_bid").select().val()
        }
        if(!obj.bid && !obj.cid) return console.log('返回了')
        localStorage.setItem('comment_add_pl_caogaoList',JSON.stringify(obj))
    }
</script>

{include file='common/scroll' /}
{include file='common/footer' /}